<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/share/_meta.jsp" %>
<%@ include file="/share/_footer.jsp" %>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/h-ui/common/jquery.editable-select.min.css" />
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理<span class="c-gray en">&gt;</span> 抄水报表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <form class="codeView docs-example" id="myform" method="post">
        <input id = "ownerName" type="text" placeholder="业主名" class="input-text radius size-L" style="width:250px" name="ownerName">
        <button type="button" class="btn btn-secondary radius size-L" onclick="query()">查&nbsp;询</button>
        <button type="button" class="btn btn-secondary radius size-L" onclick="list_info_upload();">批量上传</button>
        <button type="button" class="btn btn-secondary radius size-L" onclick="list_del();">批量删除</button>
        <button type="button" class="btn btn-secondary radius size-L" onclick="downloadWatermeterList();">导出表格</button>
    <div class="panel panel-default mt-20">
        <div class="panel-header">
            数据列表
        </div>
        <div class="panel-body">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-striped">
                <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th>小区名称</th>
                    <th>完整门牌</th>
                    <th>业主姓名</th>
                    <th>上期吨数</th>                  
                    <th>本期吨数</th>
                    <th>上期用量</th>
                    <th>本期用量</th>
                    <th>单价/吨</th>
                    <th>合计金额</th>
                    <th>抄表员</th>
                    <th>抄表时间</th>
                    <th width="100px">操作</th>
                </tr>
                </thead>
                <tbody>
                <%-- <c:forEach items="${watermeterList }" var="item">
                <tr class="text-c">
                    <td><input type="checkbox" value="" name=""></td>
                    <td>${item.housingName }</td>
                    <td>${item.building }栋${item.unit }单元${item.room }号</td>
                    <td>${item.roomOwner }</td>
                    <td>${item.oldWaterNum }</td>
                    <td>${item.waterNum }</td>
                    <td>${item.oldUseNum }</td>
                    <td>${item.useNum }</td>
                    <td>
                    <c:choose>
                    <c:when test="${item.waterUnit!=0.0}">${item.waterUnit }</c:when>
                    <c:otherwise>1.5</c:otherwise>
                    </c:choose>
                    </td>
                    <td>${item.amount }</td>
                    <td>${item.writeName }</td>
                    <td><fmt:formatDate value="${ item.createTime }"  pattern="yyyy-MM-dd HH:mm:ss"/></td>
                    <td>
                        <a title="上传账单" style="text-decoration:none" onclick="info_upload(${item.id })" href="javascript:;" class="c-success">上传账单</a><br>
                        <a title="编辑" style="text-decoration:none" onClick="info_edit(${item.id });" href="javascript:;" class="c-success">编辑</a>
                    </td>
                </tr>  
                </c:forEach> --%>                                                        
                </tbody>
            </table>
            <br>
            <br>
        </div>
    </div>
    </form>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/h-ui/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/h-ui/common/jquery.editable-select.min.js"></script>
<script type="text/javascript">
$(function(){
	queryList();
});
function query() {
	queryList();
}
function queryList(){
	$(".table-sort").dataTable().fnDestroy();
	$(".table-sort").DataTable({
		bStateSave: !0,
		aoColumnDefs: [{bSortable: false}],
		pageLength: 100,
		searching: false,
		bFilter: false,
		bSort:false,
		bStateSave: false,
		aLengthMenu:[100],
		serverSide:true,//实现后台分页
		lengthChange: false,
		bPaginate: true,
		ajax: {
			url: "${pageContext.request.contextPath}/rest/watermeter/watermeterListNew",
			dataSrc: "data",
			data: function ( d ) {
				d.roomOwner = $("#ownerName").val();
			}
		},
		/*fnDrawCallback: function () {
		 var api = this.api();
		 api.column(0).nodes().each(function (cell, i) {
		 cell.innerHTML = i + 1;
		 });
		 },*/
		aoColumns: [//列绑定
			{"data": "id"},
			{"data": "housingName"},
			{"data": "roominfoAddress"},
			{"data": "roomOwner"},
			{"data": "oldWaterNum"},
			{"data": "waterNum"},
			{"data": "oldUseNum"},
			{"data": "useNum"},
			{"data": "waterUnit"},
			{"data": "amount"},
			{"data": "writeName"},
			{"data": "createTime"}			
		],
		aoColumnDefs: [//列定义
			{
				"aTargets": [0],
				"mData": "id",
				"mRender": function (data, type, full) {
					return "<input type='checkbox' name='ids' value="+data+">";
				}
			}, {
				"aTargets": [1],
				"mData": "housingName",
				"mRender": function (data, type, full) {
					return data;
				}
			}, {
				"aTargets": [2],
				"mData": "roominfoAddress",
				"mRender": function (data, type, full) {
					return data;
				}
			},{
				"aTargets": [3],
				"mData": "ownerName",
				"mRender": function (data, type, full) {
					return data;
				}
			}, {
				"aTargets": [4],
				"mData": "oldWaterNum",
				"mRender": function (data, type, full) {
					return data;
				}
			}, {
				"aTargets": [5],
				"mData": "waterNum",
				"mRender": function (data, type, full) {
					return data;
				}
			}, {
				"aTargets": [6],
				"mData": "oldUseNum",
				"mRender": function (data, type, full) {
					return data;
				}
			}, {
				"aTargets": [7],
				"mData": "useNum",
				"mRender": function (data, type, full) {
					return data;					
				}
			}, {
				"aTargets": [8],
				"mData": "waterUnit",
				"mRender": function (data, type, full) {
					return data;
				}
			}, {
				"aTargets": [9],
				"mData": "amount",
				"mRender": function (data, type, full) {
					return data;
				}
			}, {
				"aTargets": [10],
				"mData": "writeName",
				"mRender": function (data, type, full) {
					return data;
				}
			}, {
				"aTargets": [11],
				"mData": "createTime",
				"mRender": function (data, type, full) {
					return data;
				}
			},{
				"aTargets": [12],
				"mData": "id",
				"mRender": function (data, type, full) {
					var returnHtml = "";
					if(full.status==false){
						returnHtml = "<a title='上传账单' style='text-decoration:none' onclick='info_upload("+data+")' href='javascript:;' class='c-success'>上传账单</a><br>"+
	                    "<a title='编辑' style='text-decoration:none' onClick='info_edit("+data+");' href='javascript:;' class='c-success'>编辑</a>";	
					}
					return returnHtml;			
				}
			}
		],
		language: {
			aria: {
				sortAscending: ": activate to sort column ascending",
				sortDescending: ": activate to sort column descending"
			},
			emptyTable: "没有数据",
			info: "从 _START_ 到 _END_ 共 _TOTAL_ 条",
			infoEmpty: "没有数据",
			infoFiltered: "(0 到 _MAX_ 条)",
			lengthMenu: " _MENU_",
			search: "查询:",
			zeroRecords: "没有数据",
			paginate: {previous: "<", next: ">", last: "最后一页", first: "第一页"}
		},"fnDrawCallback": function(table) {
            $("#DataTables_Table_0_info").append("  到第 <input type='text' id='changePage' class='input-text' style='width:50px;height:27px'> 页 ");
            var oTable = $(".table").dataTable();
            $('#changePage').keyup(function(e){
                if($(this).val() && $(this).val()>0){
                    var redirectpage = $(this).val()-1;
                }else{
                    var redirectpage = 0;
                }
                oTable.fnPageChange( redirectpage );
            });
        }
	})
}
function list_del() {
    layer.confirm('确认要删除吗？',function(index){
        if($(".table").find("input").is(':checked')==false){
            layer.alert("请先选择！");
            return ;
        }
		$("#myform").ajaxSubmit({
			url: "${pageContext.request.contextPath }/rest/watermeter/listDel.do",
			beforeSubmit: function () {
				layer.load();
			},
			success: function(data){
				layer.closeAll('loading');
		    	if(data.success){
		    		//layer.alert(data.message);
		    		window.location.reload();
		    	}else{
		    		layer.alert(data.message);
		    	} 
			},
			error: function(XmlHttpRequest, textStatus, errorThrown){
				layer.closeAll('loading');
				layer.alert('error!',{icon:1,time:2000});
			}
		});
    });
}
//info_upload 上传账单
function info_upload(id) {
	$.ajax({  
	    type: "POST",  
	    url: "${pageContext.request.contextPath }/rest/watermeter/infoUpload.do",  
	    dataType:"json",
	    data:{
	    	"ids":id,
	    },
	    beforeSubmit: function () {
	        layer.load();
	    },
	    success: function(data){
	    	layer.closeAll('loading');
	    	if(data.success){
	    		//layer.alert(data.message);
	    		window.location.reload();
	    	}else{
	    		layer.alert(data.message);
	    	}    	    	
	    },  
	    error: function (data){ 
	    	layer.closeAll('loading');
	    	layer.alert('error!',{icon:1,time:2000});
	    }
	});
}
//list_info_upload 批量上传账单
function list_info_upload() {
	$("#myform").ajaxSubmit({
		url: "${pageContext.request.contextPath }/rest/watermeter/infoUpload.do",
		beforeSubmit: function () {
			layer.load();
		},
		success: function(data){
			layer.closeAll('loading');
	    	if(data.success){
	    		//layer.alert(data.message);
	    		window.location.reload();
	    	}else{
	    		layer.alert(data.message);
	    	} 
		},
		error: function(XmlHttpRequest, textStatus, errorThrown){
			layer.closeAll('loading');
			layer.alert('error!',{icon:1,time:2000});
		}
	});
}
function info_edit(id){
    var index = layer.open({
        type: 2,
        title: "修改水表信息",
        content: "${pageContext.request.contextPath }/rest/watermeter/goUpdateWatermeter?id=" + id
    });
    layer.full(index);
}
function downloadWatermeterList() {    	
    var url = "${pageContext.request.contextPath }/rest/watermeter/downloadWatermeterList";
    $('#myform').attr("action", url).submit();
}
</script>